{{!

  Copyright (c) Meta Platforms, Inc. and affiliates.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

}}
{{ > Autogen}}
#pragma once

{{#program:thrift_includes}}
#include  "{{program:include_prefix}}{{program:name}}_fatal_types.h"
{{/program:thrift_includes}}

#include "{{program:include_prefix}}{{program:name}}_types.h"

#include "{{program:include_prefix}}{{program:name}}_fatal.h"

#include <fatal/type/traits.h>
#include <fatal/type/list.h>

{{ > common/namespace_cpp2_begin}}


namespace __fbthrift_refl {
namespace __fbthrift_refl_impl = ::apache::thrift::detail::reflection_impl;

{{#program:structs}}{{^struct:union?}}
class {{struct:cpp_name}}_struct_traits {
  class __fbthrift_annotations{{^field:fatal_annotations?}} : public __fbthrift_refl_impl::no_annotations{{/field:fatal_annotations?}} {
    class __fbthrift_members {
      {{#struct:fields}}
      {{#field:fatal_annotations?}}
      class __fbthrift_field_{{field:cpp_name}} {
        struct __fbthrift_keys {
          {{#field:fatal_annotations}}
          using {{annotation:safe_key}} = __fbthrift_strings_{{program:name}}::{{annotation:safe_key}};
          {{/field:fatal_annotations}}
        };

        struct __fbthrift_values {
          {{#field:fatal_annotations}}
          using {{annotation:safe_key}} = {{annotation:fatal_string}};
          {{/field:fatal_annotations}}
        };

       public:
        using keys = __fbthrift_keys;
        using values = __fbthrift_values;
        using map = ::fatal::list<
            {{#field:fatal_annotations}}
            ::apache::thrift::annotation<keys::{{annotation:safe_key}}, values::{{annotation:safe_key}}>{{^last?}},{{/last?}}
            {{/field:fatal_annotations}}
        >;
      };

      {{/field:fatal_annotations?}}
      {{/struct:fields}}
     public:
      {{#struct:fields}}
      {{#field:fatal_annotations?}}
      using {{field:cpp_name}} = ::apache::thrift::reflected_annotations<__fbthrift_field_{{field:cpp_name}}>;
      {{/field:fatal_annotations?}}
      {{^field:fatal_annotations?}}
      using {{field:cpp_name}} = __fbthrift_refl_impl::reflected_no_annotations;
      {{/field:fatal_annotations?}}
      {{/struct:fields}}
    };

    {{#struct:fatal_annotations?}}
    struct __fbthrift_keys {
      {{#struct:fatal_annotations}}
      using {{annotation:safe_key}} = __fbthrift_strings_{{program:name}}::{{annotation:safe_key}};
      {{/struct:fatal_annotations}}
    };

    struct __fbthrift_values {
      {{#struct:fatal_annotations}}
      using {{annotation:safe_key}} = {{annotation:fatal_string}};
      {{/struct:fatal_annotations}}
    };

    {{/struct:fatal_annotations?}}
   public:
    {{#struct:fatal_annotations?}}
    using keys = __fbthrift_keys;
    using values = __fbthrift_values;
    using map = ::fatal::list<
        {{#struct:fatal_annotations}}
        ::apache::thrift::annotation<keys::{{annotation:safe_key}}, values::{{annotation:safe_key}}>{{^last?}},{{/last?}}
        {{/struct:fatal_annotations}}
    >;
    {{/struct:fatal_annotations?}}
    using members = __fbthrift_members;
  };

  {{#struct:fields}}
  struct __fbthrift_member_{{field:cpp_name}} {
    using owner = {{struct:cpp_fullname}};
    using name = __fbthrift_strings_{{program:name}}::{{field:name_hash}};
    using type = {{field:cpp_type}};
    using tag = ::apache::thrift::ident::{{field:cpp_name}};
    static constexpr ::apache::thrift::field_id_t id = {{field:key}};
    static constexpr auto optional = ::apache::thrift::optionality::{{field:fatal_required_qualifier}};
    {{#field:type}}{{#type:cpp_indirection?}}
    using getter = __fbthrift_refl_impl::chained_data_member_accessor<
        __fbthrift_refl_impl::data_member_accessor<::apache::thrift::ident::{{field:cpp_name}}>,
        ::apache::thrift::detail::apply_indirection_fn
    >;
    using field_ref_getter = ::apache::thrift::access_field_fn<::apache::thrift::ident::{{field:cpp_name}}>;
    {{/type:cpp_indirection?}}{{/field:type}}
    {{#field:type}}{{^type:cpp_indirection?}}
    using getter = __fbthrift_refl_impl::data_member_accessor<::apache::thrift::ident::{{field:cpp_name}}>;
    using field_ref_getter = ::apache::thrift::access_field_fn<::apache::thrift::ident::{{field:cpp_name}}>;
    {{/type:cpp_indirection?}}{{/field:type}}
    using type_class = {{#field:type}}{{type:type_class}}{{/field:type}};
    using annotations = ::apache::thrift::reflected_annotations<__fbthrift_annotations::members::{{field:cpp_name}}>;
  };
  {{/struct:fields}}

  struct __fbthrift_member {
    {{#struct:fields}}
    using {{field:cpp_name}} = ::apache::thrift::reflected_struct_data_member<__fbthrift_member_{{field:cpp_name}}>;
    {{/struct:fields}}
  };
 public:
  using type = {{struct:cpp_fullname}};
  using name = __fbthrift_strings_{{program:name}}::{{struct:cpp_name}};
  using member = __fbthrift_member;
  using members = ::fatal::list<
      {{#struct:fields}}
      member::{{field:cpp_name}}{{^last?}},{{/last?}}
      {{/struct:fields}}
  >;
  using members_annotations = __fbthrift_annotations::members;
  using metadata = ::apache::thrift::detail::type_common_metadata_impl<
      {{program:name}}_tags::module,
      ::apache::thrift::reflected_annotations<__fbthrift_annotations>,
      static_cast<::apache::thrift::legacy_type_id_t>({{struct:legacy_type_id}}ull)
  >;
};

{{/struct:union?}}{{/program:structs}}
} // __fbthrift_refl

{{#program:structs}}{{^struct:union?}}
THRIFT_REGISTER_STRUCT_TRAITS({{#struct:extra_namespace}}{{struct:extra_namespace}}::{{/struct:extra_namespace}}{{struct:cpp_name}}, __fbthrift_refl::{{struct:cpp_name}}_struct_traits);
{{/struct:union?}}{{/program:structs}}
{{ > common/namespace_cpp2_end}}
